package com.sen.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sen.common.api.ApiResult;
import com.sen.model.entity.BmsBillboard;
import com.sen.service.IBmsBillboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/billboard")
public class BmsBillBoardController extends BaseController{

    //依赖注入
    @Resource
    private IBmsBillboardService bmsBillboardService;

    /**
     * 展示公告，在数据库中最后（最新）一条信息
     * @return BmsBillboard
     */
    @GetMapping("/show")
    public ApiResult<BmsBillboard> getNotices(){
        //增加查询条件 字段show为1的时候显示
        List<BmsBillboard> list = bmsBillboardService.list(new
                LambdaQueryWrapper<BmsBillboard>().eq(BmsBillboard::isShow,true));
        return ApiResult.success(list.get(list.size()-1));
    }
}
